%%% Parameter Calibration
% clear
%% Problem
d = 2;
x_bound = repmat([-6,6],[d,1]);
OptSet.sol = [3,2;
    -2.805118,3.131312;
    -3.779310,-3.283186;
    3.584428,-1.848126];
OptSet.fval = 0;

OptSet.epsilon = 0.001;
OptSet.radius = 0.1;
%%
precision = 0.003;
NewRegionNum = 2;
MaxPartitionDepth_d = ceil(log((x_bound(:,2)-x_bound(:,1))./precision)...
    ./log(NewRegionNum));
MaxPartitionDepth = sum(MaxPartitionDepth_d)
ClearRadius0 = (x_bound(:,2)-x_bound(:,1))./(NewRegionNum.^(MaxPartitionDepth_d));
ClearRadius = sqrt(sum(ClearRadius0.^2)); % the maximum distance within a non-partitionable region

Problem.Dimension = d;
Problem.Domain = reshape(x_bound',[1,d*2]);
Problem.Sampling = @Sampling_BoxConstraint;
Problem.Partition = @(Region,SampleSet)Partition_NP_BoxConstraint(Region, NewRegionNum, MaxPartitionDepth, SampleSet);

%% DOE Setting
n0 = [4,6,8];
QuantileLevel = [0.1,0.15,0.2,0.25];
NewBudget = [3,5,8];
MaxSampleSize = [10,15,20];

diff = fullfact([length(n0), length(QuantileLevel), length(NewBudget), length(MaxSampleSize)]);
diff = [(n0(diff(:,1)))', (QuantileLevel(diff(:,2)))', (NewBudget(diff(:,3)))', (MaxSampleSize(diff(:,4)))'];
rep=50;
Totbudget = zeros(size(diff,1),rep);
%%
for i=1:rep
    i
    tic
    for idiff = 1:size(diff,1)
        %% Algorithm
        AlgorithmM.n0 = diff(idiff,1);
        AlgorithmM.QuantileLevel = diff(idiff,2);
        AlgorithmM.NewBudget = diff(idiff,3);
        AlgorithmM.MaxSampleSize = diff(idiff,4);
        AlgorithmM.StopCriteria = [1,300000];
        AlgorithmM.radius = ClearRadius;
        %% PRS-MMO
        [~, ~, SampleSet] = PRS_MMO_test( Problem, AlgorithmM, OptSet );
        Totbudget(idiff,i) = size(SampleSet,1);
    end
    toc
end
clear i idiff j SampleSet ClearRadial0
% save(['Shubert_D2_',num2str(NewRegionNum),'region_v0.mat'])